package com.gitee.feizns.web.mvc.validate.annotation;

import com.gitee.feizns.web.dao.ar.AbstractModel;
import com.gitee.feizns.web.mvc.validate.NotExistsValidator;

import javax.validation.Constraint;
import javax.validation.Payload;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

import static java.lang.annotation.ElementType.ANNOTATION_TYPE;
import static java.lang.annotation.ElementType.CONSTRUCTOR;
import static java.lang.annotation.ElementType.FIELD;
import static java.lang.annotation.ElementType.METHOD;
import static java.lang.annotation.ElementType.PARAMETER;
import static java.lang.annotation.ElementType.TYPE_USE;

/**
 * 存在就报错
 * @author feizns
 * @since 2019/7/20
 */
@Target({ METHOD, FIELD, ANNOTATION_TYPE, CONSTRUCTOR, PARAMETER, TYPE_USE })
@Retention(RetentionPolicy.RUNTIME)
@Constraint(validatedBy = NotExistsValidator.class)
public @interface NotExists {

    /**
     * 验证是否存在
     * @return
     */
    Class<? extends AbstractModel> value();

    /**
     * 验证的字段
     * @return
     */
    String field() default "";

    /**
     * 是否必须
     * @return
     */
    boolean required() default true;

    /**
     * 拼接WHERE
     * @return
     */
    String where() default "";

    /**
     * 错误码key
     * @return
     */
    String code() default "";

    /**
     * 消息
     * @return
     */
    String message() default "";

    /**
     * 分组
     * @return
     */
    Class<?>[] groups() default {};

    /**
     * 负载
     * @return
     */
    Class<? extends Payload>[] payload() default {};

}
